$(document).ready(function () {
    fplx.onLoad();
})

var fplx = (function () {
    var curSeg;
    var notEmpty = true;
    var init = function () {
        $('#picCode').attr("src", queryHtp + '/bsfwt/sscx/showPictureCode.do?t=' + Math.random());
    };

    return {
        onLoad: function () {
            init();
            curSeg = fplx;
            curSeg.onLayui();
        },

        //加载layui
        onLayui: function () {
            layui.use('form', function () {
                var form = layui.form
            });
            layui.use('laydate', function () {
                var laydate = layui.laydate;
                laydate.render({
                    elem: '#wxl_date1',
                    theme: 'molv'
                });
            })
        },

        //加载数据
        onQuery: function () {
            if (notEmpty == false) {
                return false;
            }
            if (curSeg.inputIsEmpty()) {

            } else {
                var FPDM = $(":input[name='FPDM']").val().trim();
                var FPHM = $(":input[name='FPHM']").val().trim();
                var NSRSBH = $(":input[name='NSRSBH']").val().trim();
                var rcode = $(":input[name='rcode']").val().trim()

                $(":input[name='rcode']").val('');

                notEmpty = false;
                $.ajax({
                    url: queryHtp + "/bsfwt/sscx/getFpzwcxNew.do",
                    type: "GET",
                    data: {
                        FPDM: FPDM,
                        FPHM: FPHM,
                        NSRSBH: NSRSBH,
                        rcode: rcode,
                        ACTION: 'getFpzw'
                    },
                    dataType: "jsonp",
                    jsonpCallback: "fplx.onqueryCallback",
                });
            }



        },
        onqueryCallback: function (jsonObj) {
            notEmpty = true;
            curSeg.reloadPicCode();

            switch (jsonObj.code) {
                case "0":
                    if (jsonObj.data.rtn.length < 1) {
                        layui.use('layer', function () {
                            var layer = layui.layer;
                            layer.msg("未查询到数据");
                        })
                        break;
                    }
                    if ($.fn.dataTable.isDataTable('#wxlYbnsrcx')) {
                        var table = $('#wxlYbnsrcx').DataTable();
                        table.destroy();
                    }
                    $('#wxlYbnsrcx').DataTable({
                        "data": jsonObj.data.rtn,
                        "columns": [{
                                "data": "NSRSBH"
                            },
                            {
                                "data": "NSRMC"
                            },
                            {
                                "data": "FPZL_MC"
                            },
                            {
                                "data": "NSRZT_MC"
                            },
                            {
                                "data": "RQ"
                            }
                        ],
                        "ordering": false,
                        "info": false,
                        "lengthChange": false,
                        "searching": false,
                        "paging": false
                    })
                    break;
                default:
                    layui.use('layer', function () {
                        var layer = layui.layer;
                        layer.msg(jsonObj.msg);
                    })
            }
        },

        //验证码
        reloadPicCode: function () {
            // http://jcpt.ha-n-tax.gov.cn
            $('#picCode').attr("src", queryHtp + '/bsfwt/sscx/showPictureCode.do?t=' + Math.random());
        },

        winReset: function () {
            $(":input[type=text]").val('');
            $("#wxlYbnsrcx tbody").empty();
        },

        //判断输入信息是否为空并提示
        inputIsEmpty: function () {
            var flag = false;
            $('input').each(function () {
                var that = this;
                if ($(this).val() == "") {
                    if ($(this).hasClass("layui-input")) {

                    } else {
                        layui.use('layer', function () {
                            var layer = layui.layer;
                            layer.msg($(that).attr("data-name") + '不能为空');
                        })
                        flag = true;
                        return false;
                    }

                }
            })
            return flag;
        }
    }
})();